package com.ruoyi.flowable.listener.move;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.equ.domain.EquMove;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 移动-5监听
 */
@Slf4j
@Component("moveListener_5")
public class MoveListener_5 implements ExecutionListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void notify(DelegateExecution execution) {
        try {
            EquMove equMove = execution.getVariable("equMove", EquMove.class);
            Map<String, Object> executeInfoMap = objectMapper.readValue(equMove.getExecuteInfo(), new TypeReference<Map<String, Object>>() {});
            HashMap<String, Object> dataMap = new HashMap<>();
            dataMap.put("搬运路线是否通畅", execution.getVariable("flag5", String.class));
            dataMap.put("搬运路线通畅具体情况", execution.getVariable("detailInfo5", String.class));
            dataMap.put("后勤支持", execution.getVariable("support5", String.class));
            executeInfoMap.put("后勤保障部门审批", dataMap);
            String executeInfo = objectMapper.writeValueAsString(executeInfoMap);

            equMove.setExecuteInfo(executeInfo);
            execution.setVariable("equMove", equMove);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
